<?php

namespace frontend\modules\AmoebaForm\controllers;

use common\models\c2\entity\Amoeba;
use common\models\c2\entity\AmoebaFormItem;
use frontend\controllers\BaseController;
use Yii;
use yii\helpers\Url;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
 * Default controller for the `amoeba-form` module
 */
class DefaultController extends BaseController
{

    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex($id = null)
    {
        // $this->navActive = 2;

        $this->layout = '/empty';
        $userId = Yii::$app->user->id;
        $amoebaFormItemModel = AmoebaFormItem::find()
            ->where(['user_id' => $userId, 'seo_code' => $id])->one();
        if (is_null($amoebaFormItemModel)) {
            throw new NotFoundHttpException(Yii::t('app.c2', 'Params Error'));
        }

        $model = Amoeba::findOne($amoebaFormItemModel->amoeba_id);
        //ZF20190719XN20
        return $this->render('index', [
            'model' => $model
        ]);
    }

    public function actionList()
    {
        $this->navActive = 2;
        $user_id = Yii::$app->user->id;
        $models = AmoebaFormItem::find()->where(['user_id' => $user_id])->all();
        return $this->render('list', [
            'models' => $models
        ]);
    }

    public function afterAction($action, $result)
    {
        return parent::afterAction($action, $result); // TODO: Change the autogenerated stub
    }
}
